<template>
  <div class="content">
    <div class="login">
      <div class="login-div">
        <div class="login-wecome">
          <p class="title">Welcome Back!</p>
          <p class="dsc">
            To keep connected with us please login with your personal info
          </p>
        </div>
        <div class="login-msg">
          <div class="lognText">
            <p>Reg<span>ister</span></p>
          </div>
          <div class="loginInput">
            <label for="">Email</label>
            <input
              v-model="form.email"
              type="text"
              placeholder="Please enter email"
            >
          </div>
          <div class="loginInput">
            <label for="">User name</label>
            <input
              v-model="form.account"
              type="text"
              autocomplete="off"
              placeholder="enter one user name"
            >
          </div>
          <div class="loginInput">
            <label for="">Password</label>
            <input
              v-model.trim="form.password"
              type="password"
              autocomplete="new-password"
              placeholder="Please input a password"
            >
          </div>
          <div class="loginInput last">
            <label for="">Confirm password</label>
            <input
              v-model.trim="form.confirmPassword"
              type="password"
              autocomplete="new-password"
              placeholder="Please confirm the password"
            >
          </div>
          <div class="agreement">
            <el-checkbox
              v-model="checked"
            >I accept the Shopmell's
              <router-link
                target="_blank"
                to="/termsofservice"
              >Terms of Service</router-link>
              And
              <router-link
                target="_blank"
                to="/privacy"
              >Privacy Policy</router-link></el-checkbox>
          </div>
          <div class="btn1">
            <div class="btnS">
              <router-link to="/home/login">
                Tologin
              </router-link>
            </div>
            <div v-preventReClick class="btnS" @click="registerBtn">
              Register
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { registerPage } from '@/api/article';
export default {
  data() {
    return {
      form: {},
      checked: false
    };
  },
  mounted() {
    this.$nextTick(function() {
      if (
        document.documentElement.clientHeight >
        document.getElementsByClassName('content')[0].clientHeight
      ) {
        document.getElementsByClassName('content')[0].style.minHeight =
          document.documentElement.clientHeight -
          document.getElementsByClassName('header')[0].clientHeight -
          document.getElementsByClassName('footer')[0].clientHeight +
          'px';
      } else {
        document.getElementsByClassName('content')[0].style.minHeight =
          950 + 'px';
      }
    });
  },
  methods: {
    registerBtn() {
      if (!this.checked) {
        return;
      }
      if (!this.form.email) {
        this.$message.warning('Please Enter Email');
        return;
      } else {
        var reg = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
        if (!reg.test(this.form.email)) {
          this.$message.warning('Please enter a valid email');
          return;
        }
      }
      if (!this.form.account) {
        this.$message.warning('Please Enter account');
        return;
      } else {
        if (this.form.account.length > 50) {
          this.$message.warning(
            'The maximum length of the user name is 50 characters'
          );
          return;
        }
        if (this.form.account.length < 5) {
          this.$message.warning(
            'The user name should be at least 5 characters long'
          );
          return;
        }
      }
      if (!this.form.password) {
        this.$message.warning('Please Enter password');
        return;
      } else {
        if (this.form.password.length < 8) {
          this.$message.warning(
            'Please Enter password minimum Enter eight length'
          );
          return;
        }
        if (this.form.password.length > 20) {
          this.$message.warning(
            'The maximum length of the user name is 20 characters'
          );
          return;
        }
      }
      if (!this.form.confirmPassword) {
        this.$message.warning('Please Enter confirmPassword');
        return;
      } else {
        if (this.form.confirmPassword.length < 8) {
          this.$message.warning(
            'Please Enter password minimum Enter eight length'
          );
          return;
        }
      }
      if (this.form.password && this.form.confirmPassword) {
        if (this.form.password !== this.form.confirmPassword) {
          this.$message.warning('Two Different passwords');
          return;
        }
      }
      registerPage(this.form).then((res) => {
        if (res.code === 200) {
          this.$message.success('register was successful, Please to login！');
        } else {
          this.$message.warning(
            'Registration failed, please check the parameters！'
          );
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.content {
  width: 100%;
  height: 100%;
  margin-top: 70px;
  background: url('../../assets/loginImgs/regBg.png') no-repeat;
  background-size: 100% 100%;
  font-family: Segoe UI;
}
.login {
  text-align: center;
  max-height: 1200px;
  min-height: 970px;
  overflow: hidden;
  &-div {
    max-width: 1200px;
    width: 1000px;
    margin: 0 auto;
    margin-top: calc(100vw / 18.11);
  }
  &-wecome {
    width: 330px;
    height: 680px;
    display: inline-block;
    padding-top: 285px;
    background: url('../../assets/loginImgs/regLeft.png') no-repeat;
    background-size: 100% 100%;
    .title {
      font-size: 32px;
      font-weight: bold;
      line-height: 37px;
      color: #ffffff;
    }
    .dsc {
      font-size: 16px;
      font-weight: normal;
      line-height: 20px;
      padding: 10px;
      color: #ffffff;
    }
  }
  &-msg {
    width: 664px;
    height: 680px;
    display: inline-block;
    vertical-align: top;
    background: rgba(255, 255, 255, 1);
    box-shadow: 0px calc(100vw / 960) calc(100vw / 192) rgba(0, 0, 0, 0.2);
    .lognText {
      text-align: center;
      margin: 40px 0;
      p {
        font-size: 44px;
        color: #999999;
        font-weight: bold;
        span {
          color: #02a152;
        }
      }
    }
    .agreement {
      width: 664px;
      margin: 20px 0;
      text-align: center;
      a {
        text-decoration: underline;
        &:hover {
          color: rgba(2, 161, 82, 1);
        }
      }
    }
    .loginInput {
      margin: 0 auto;
      margin-bottom: 20px;
      &.last {
        margin-bottom: 15px;
      }
      label {
        font-size: 20px;
        // padding-right: calc(100vw / 128);
        width: 448px;
        display: inline-block;
        text-align: left;
        color: #cccccc;
      }
      input {
        width: 448px;
        height: 48px;
        color: #666666;
        font-size: 18px;
        outline: none;
        border: none;
        border-bottom: 1px solid #cccccc;
      }
    }
    .btn1 {
      width: 100%;
      height: 54px;
      margin-bottom: 20px;
      display: flex;
      justify-content: space-between;
      .btnS {
        width: 160px;
        height: 54px;
        font-size: 26px;
        display: inline-block;
        margin: 0 auto;
        color: #ffffff;
        line-height: 54px;
        background: rgba(2, 161, 82, 1);
        // box-shadow: 0px 0px calc(100vw / 320) rgba(0, 0, 0, 0.16);
        border-radius: 4px;
      }
    }
  }
}
</style>
